package com.example.aitoedu.controller;

import cn.dev33.satoken.util.SaResult;
import com.example.aitoedu.entity.TsTalk;
import com.example.aitoedu.service.TsTalkService;
import com.example.aitoedu.vo.AllUserTalkVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/logic/user/talk")
@Slf4j
@CrossOrigin
@Tag(name = "学生和老师对话相关接口")
public class UserTalkController {

    @Autowired
    private TsTalkService tsTalkService;

    @GetMapping("/allConversation")
    @Operation(summary = "查询和老师或学生的全部对话，按照最新对话时间从新到旧排序")
    public SaResult allConversation(){
        List<AllUserTalkVO> lists = tsTalkService.allConversation();
        return SaResult.ok().setData(lists);
    }

    @GetMapping("/onlyConversation")
    @Operation(summary = "查询和某一个人的全部对话")
    public SaResult onlyConversation(Long id){
        List<TsTalk> tsTalks = tsTalkService.onlyConversation(id);
        return SaResult.ok().setData(tsTalks);
    }

    @GetMapping("/setRead")
    @Operation(summary = "将未读消息变已读")
    public SaResult setRead(Long id){
        tsTalkService.setRead(id);
        return SaResult.ok();
    }
}
